using CardGameObject.GameScene;
using Common;
using Entity;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace CardGameObject.CollectScene
{
    public class CardDetail : MonoBehaviour
    {
        public Image CardImage;
        public Image CardRare;
        public TextMeshProUGUI NameText;
        public TextMeshProUGUI AttackText;
        public TextMeshProUGUI HealthText;
        public TextMeshProUGUI CostText;
        public TextMeshProUGUI EffectText;
        public TextMeshProUGUI CountText;

        public void SetCardInfo(CollectCardVO card)
        {
            AttackText.text = card.Attack.ToString();
            HealthText.text = card.Health.ToString();
            CostText.text = card.Cost.ToString();
            EffectText.text = card.EffectText;
            NameText.text = card.CardName;
            CountText.text = "X " + card.CardCount;
            
            // 设置卡牌稀有度
            CardRarityEnum cardRarity = (CardRarityEnum)card.CardRarity;
            switch (cardRarity)
            {
                case CardRarityEnum.N:
                    CardRare.color = Color.white;
                    break;
                case CardRarityEnum.R:
                    CardRare.color = Color.blue;
                    break;
                case CardRarityEnum.SR:
                    CardRare.color = new Color(1f, 0.84f, 0f); // 金黄色
                    break;
                case CardRarityEnum.UR:
                    CardRare.color = Color.red;
                    break;
                default:
                    Debug.LogWarning($"未处理的卡牌稀有度: {cardRarity}");
                    break;
            }
            
            Sprite sprite = Resources.Load<Sprite>($"Images/CardImage/Content/{card.CardName}");

            if (sprite != null)
            {
                CardImage.sprite = sprite;
            }
        }
    }
}
